<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>学生基础数据采集</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" type="text/css" href="/layui/css/layui.css"/>
</head>


<script type="text/javascript" src="/layui/layui.js"></script>
<script type="text/javascript" src="/layui/layui.all.js"></script>
<script type="text/javascript" src="/js/jquery-2.0.3.min.js"></script>
<body>
<div th:if="${message}">
    <h2 th:text="${message}"/>
</div>
<div id="box">
    <input type="text" name="search" placeholder="请输入身份证" id="idCard">
    <input type="text" name="search" placeholder="请输入学生姓名" id="studentName">
    <button id="search" type="button" class="layui-btn layui-btn-normal">搜索</button>

</div>
<div>
    <form method="post" enctype="multipart/form-data" action="/upLoadStudentBasicInfo">
        <table>
            <tr>
                <td>上传文件：</td>
                <td><input type="file" name="file" /></td>
            </tr>

            <tr>
                <td></td>
                <td><input type="submit" value="上传" /></td>
            </tr>
        </table>
    </form>


</div>
<button type="button" onclick="downExcel()">基础数据表模板下载</button>
<div>
    <ul>
        <li th:each="file : ${files}">
            <a th:href="${file}" th:text="${file}" />
        </li>
    </ul>
</div>
<table id="test3" lay-filter="test3" class="layui-hide"></table>
<script>
    function findData(idCard,teacherName){
        layui.use('table', function () {
            var table = layui.table;
            table.render({
                elem: '#test3'
                ,url:'findAllStudentBasicData'
                ,parseData: function(res) {
                    return {
                        "code":'0', //解析接口状态
                        "msg": res.msg, //解析提示文本
                        "count":res.count, //解析数据长度
                        "data": res.data //解析数据列表
                    }
                }
                , cols: [
                    [
                        {title: '序号', type: 'numbers', Width: 20}
                        , {field: 'studentName', title: '学生姓名', edit: 'text', minWidth: 80}
                        , {field: 'idCard', title: '身份证', edit: 'text', minWidth: 180, sort: true}
                        , {field: 'studentBirthday', title: '出生年月', minWidth: 80, edit: 'text'}
                        , {field: 'entrance', title: '入学口', minWidth: 100, edit: 'text'}
                        , {field: 'studentXJ', title: '学籍状态', minWidth: 80, edit: 'text'}
                        , {field: 'studentRegistrationNo', title: '学籍注册号', minWidth: 80, edit: 'text'}
                    ]
                ]
                , page: true
                ,where : {
                    idCard:idCard,
                    teacherName:teacherName
                }
                , done: function (res, curr, count) {
                    debugger;
                    for (var i = 0; i < res.data.length; i++)   //遍历返回数据
                    {
                        if (res.data[i].achievement > 100 || res.data[i].achievement < 0)    //设置条件
                        {
                            $("table tbody tr").eq(i + 2).find('td').eq(7).css('color', 'red')    //改变满足条件行的颜色
                        }
                    }
                }

            });
            table.on('edit(test3)', function (obj) {
                debugger;
                var value = obj.value //得到修改后的值
                    , data = obj.data //得到所在行所有键值
                    , field = obj.field; //得到字段
                layui.use('jquery', function () {
                    var $ = layui.$;
                    $.ajax({
                        type: 'get',
                        url: "updateStudentBasicData", // ajax请求路径
                        data: {
                            id: data.id,
                            field: field,
                            value: value
                        },
                        success: function (data) {
                            $("#test3").empty();
                            table.reload("test3", { //此处是上文提到的 初始化标识id
                                page:{
                                    curr: 1
                                }
                            });
                            layer.msg('修改成功');
                        }
                    });
                });
            })

        })
    }
    $("#search").click(function () {
        debugger;
        var idCard=$("#idCard").val();
        var teacherName=$("#studentName").val();
        findData(idCard,teacherName);
    })
    $(function(){
        findData(null,null);
    });

</script>
<script>
    function downExcel() {
        // window.open("http://127.0.0.1:8093/studentBasicFiles");
        window.open("http://192.168.7.22:8093/studentBasicFiles");
    }
</script>
</body>
</html>